<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title2</title>
    <script src="js/jquery-3.6.0.min.js"></script>
    <style>
        .dv1{
            width: 50%;
            float: left;
            border: 1px solid red;
        }
        .dv2{
            width: 40%;
            margin-right: 8%;
            float: right;
            border: 1px solid green;
        }
        input,label,select,button{
            padding: 10px;
        }

    </style>
</head>
<body>
<div>

          <div>
              <label>连接人：</label><input id="ip2">
          </div>
          <div><button onclick="connect()">开始连接</button></div>
    </div>
</div>
<script>
    var ws;

    function connect(){
        // 打开一个 web socket
        ws = new WebSocket("ws://124.221.58.106:8082/server/"+$("#ip2").val());
        ws.onopen = function()
        {
            ws.send($("#ip2").val()+"已连接到，等待推送……");
        };
        ws.onmessage = function (evt)
        {
            var msg = evt.data;
            alert("消息------>"+msg)
        };
        ws.onclose = function()
        {};
    }
</script>

</body>
</html>